<?php
/*Greg*/
function getCategoryFromCropId($cropid){
	if($cropid == null) die("No cropid specified");
	$con = connect_db();
	$sql = "select categoryid from CROP where cropid=$cropid";
	$result = mysql_fetch_array(mysql_query($sql, $con));
	mysql_close($con);
	if(count($result) < 1) die("No crop with cropid=$cropid found");
	
	return $result[0];
}
function getQuantity($cropid){
	if($cropid == null) die("No cropid specified");
	$con = connect_db();
	$sql = "select quantity from AMOUNT_HARVESTED where cropid=$cropid";
	$result = mysql_fetch_array(mysql_query($sql, $con));
	mysql_close($con);
	if(count($result) < 1) die("No crop with cropid=$cropid found");
	return $result[0];
}
function getCost($cropid){
	if($cropid == null) die("No cropid specified");
	$con = connect_db();
	$sql = "select cost from SEEDS_PURCHASED where cropid=$cropid";
	$result = mysql_fetch_array(mysql_query($sql, $con));
	mysql_close($con);
	if(count($result) < 1) die("No crop with cropid=$cropid found");
	return $result[0];
}
function getSeason($cropid){
	if($cropid == null) die("No cropid specified");
	$con = connect_db();
	$sql = "select season from CROP where cropid=$cropid";
	$result = mysql_fetch_array(mysql_query($sql, $con));
	mysql_close($con);
	if(count($result) < 1) die("No crop with cropid=$cropid found");
	return $result[0];
}
function getPlantTime($cropid){
	if($cropid == null) die("No cropid specified");
	$con = connect_db();
	$sql = "select startDate from PLANTS_ADDED where cropid=$cropid";
	$result = mysql_fetch_array(mysql_query($sql, $con));
	mysql_close($con);
	if(count($result) < 1) die("No crop with cropid=$cropid found");
	return $result[0];
}
function getHarvestTime($cropid){
	if($cropid == null) die("No cropid specified");
	$con = connect_db();
	$sql = "select startDate from AMOUNT_HARVESTED where cropid=$cropid";
	$result = mysql_fetch_array(mysql_query($sql, $con));
	mysql_close($con);
	if(count($result) < 1) die("No crop with cropid=$cropid found");
	return $result[0];
}
function getPestIssues($cropid){
	if($cropid == null) die("No cropid specified");
	$con = connect_db();
	$sql = "select notes from PEST_WEED_LOG where cropid=$cropid";
	$result = mysql_fetch_array(mysql_query($sql, $con));
	mysql_close($con);
	if(count($result) < 1) die("No crop with cropid=$cropid found");
	return $result[0];
}
function getAllCropnames() {
	$con = connect_db();
	$sql = "select cropname from CROP";
	$result = mysql_fetch_array(mysql_query($sql, $con));
	mysql_close($con);
	if(count($result) < 1) die("No crop with cropid=$cropid found");
	return $result[0];
}